window.addEventListener('pagehide', function(event) {
    layer.closeAll();
})
// 提示跳转到其他浏览器
$(window).on("load", function() {
    var winHeight = $(window).height();

    function is_weixin() {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true;
        } else {
            return false;
        }
    }
    var isWeixin = is_weixin();
    if (isWeixin) {
        $(".weixin-tip").css("height", winHeight);
        $(".weixin-tip").show();
    }

    // $.ajax({
    // 	type: "POST", //用POST方式传输
    // 	dataType: "JSON", //数据格式:JSON
    // 	url: '/cple/getRegnumber', //目标地址
    // 	success: function(msg) {
    // 		// console.log(msg)
    // 		var regnumber = msg.regnumber;
    // 		$(".hiddenCenterAbc").html(regnumber);
    // 	}
    // });
})
//获取图形验证码

// 校验手机号获取验证码
$('.code_font_color').click(function() {
    var code = $("#code").val(); //验证码
    var phone = $("#telephone").val(); //手机号码
    var telephones = $("#telephones").val();
    var reg_phone = /^1[3456789]\d{9}$/;
    $('#img').attr("src", "https://h5.honeytrip.cn/QRcode/getRand?session_id=" + phone + "&a=" + Math.random());
    if (!reg_phone.test(phone)) { //验证手机是否符合格式
        // $("#checkExistPhone").html("× 请正确输入手机号！");
        layer.open({
            content: '请正确输入手机号！',
            skin: 'msg',
            time: 2, //2秒后自动关闭
            fixed: false,
            top: 300
        });
        return false;
    } else {
        $.confirm({
            title: '图形验证码',
            content: '' +
                '<div id="form_login">' +
                '<div class="section">' +
                '<input type="text"  placeholder="请输入图形验证码" id="telephones" maxlength="11" />' +
                '</div>' +
                '<div style="width: 5rem;margin: 0.5rem auto;">' +
                '<img style="margin: 0 auto;width:66%" src="https://h5.honeytrip.cn/QRcode/getRand?session_id=" +phone + "&a=" + Math.random() alt="" id="img">' +
                '</div>' +
                '</div>',
            onContentReady: function() {
                var jc = this;
                var phone = $("#telephone").val();
                var getimagecode = this.$content.find('#img').attr("src",
                    "https://h5.honeytrip.cn/QRcode/getRand?session_id=" + phone +
                    "&a=" + Math.random());
                this.$content.find('img').on('click', function(e) {
                    console.log('111111')
                    //手机号码
                    var getimagecode = $('#img').attr("src", "https://h5.honeytrip.cn/QRcode/getRand?session_id=" + phone +
                        "&a=" + Math.random());
                });
            },
            buttons: {
                formSubmit: {
                    text: '确认',
                    btnClass: 'btn-blue',
                    action: function() {
                        var name = this.$content.find('#telephones').val();
                        if (!name) {
                            $.alert('请输入图形验证码！');
                            return false;
                        }
                        //请求短信接口
                        var count = 120;
                        var code = $("#code").val(); //验证码
                        var phone = $("#telephone").val(); //手机号码
                        var reg_phone = /^1[3456789]\d{9}$/;
                        // 向后台发送处理数据
                        var jon = {
                            mobile: Number(phone),
                            verifCode: name
                        }
                        $.ajax({
                            type: "GET", //用GET方式传输
                            dataType: "JSON", //数据格式:JSON
                            url: 'https://h5.honeytrip.cn/sms/sendsms', //目标地址
                            data: jon,
                            success: function(res) {
                                console.log(res)
                                var success = res.success;
                                var msg = res.mag;
                                if (success == true) {
                                    //开始计时
                                    $(".code_font_color").attr('disabled', 'disabled');
                                    $(".code_font_color").html("倒计时" + count + "秒");
                                    var timer = setInterval(function() {
                                        count--;
                                        $(".code_font_color").html("倒计时" + count + "秒");
                                        if (count == 0) {
                                            clearInterval(timer);
                                            $(".code_font_color").attr("disabled", false); //启用按钮
                                            $(".code_font_color").html("重新发送验证码");
                                            code = ""; //清除验证码。如果不清除，过时间后，输入收到的验证码依然有效
                                        }
                                    }, 1000);
                                } else {
                                    layer.open({
                                        content: res.msg,
                                        skin: 'msg',
                                        time: 2, //2秒后自动关闭
                                        fixed: false,
                                        top: 300
                                    });

                                }
                            }
                        });
                    }
                },
                formSubmits: {
                    text: '取消',
                },

            },

        });
    }

});


//点击获取图形验证
// $('.lingqus').click(function() {

// 	$(".block").show();
// 	$(".zongs").hide();
// });
// 领取cple点击事件
$(document).on("touchstart", ".lingqu", function() {
    var reg_code = /^\d{6}$/;
    var yqcode = $("#yqcode").val(); //邀请码
    var code = $("#code").val(); //验证码
    var phone = $("#telephone").val(); //手机号码
    if (reg_code.test(code) && code !== '' && phone !== '' && yqcode !== '') {
        var jonOB = {
            mobile: parseInt(phone),
            verifyCode: code,
            shareId: yqcode
        };
        $.ajax({
            type: "GET", //用GET方式传输
            dataType: "JSON", //数据格式:JSON
            url: 'https://h5.honeytrip.cn/user/login', //目标地址
            data: jonOB,
            success: function(res) {
                console.log(res)
                var msg = res.msg;
                if (res.success == true) {
                    $(".block").hide();
                    $(".hidden").show();
                } else {
                    // $("#checkExistPhone").html(msg);
                    layer.open({
                        content: res.msg,
                        skin: 'msg',
                        time: 2, //2秒后自动关闭
                        fixed: false,
                        top: 300
                    });
                }
            },
            error: function(msy) {

            }
        });
    } else if (phone == '') {
        // $("#checkExistPhone").html("× 请输入手机号！");
        layer.open({
            content: " 请输入手机号！",
            skin: 'msg',
            time: 2, //2秒后自动关闭
            fixed: false,
            top: 300
        });
    } else if (code == '') {
        // $("#checkExistPhone").html("× 请输入（获取）验证码！");
        layer.open({
            content: " 请输入短信验证码！",
            skin: 'msg',
            time: 2, //2秒后自动关闭
            fixed: false,
            top: 300
        });
    } else if (yqcode == '') {
        // $("#checkExistPhone").html("× 请输入邀请码！");
        layer.open({
            content: " 请输入邀请码！",
            skin: 'msg',
            time: 2, //2秒后自动关闭
            fixed: false,
            top: 300
        });
    } else {
        // $("#checkExistPhone").html("× 请正确填写手机号、验证码、邀请码");
        layer.open({
            content: " 请正确填写手机号、验证码、邀请码！",
            skin: 'msg',
            time: 2, //2秒后自动关闭
            fixed: false,
            top: 300
        });
    }
});

// 验证码手机号获取焦点
$("#code,#telephone,#telePassworld").focus(function() {
    $("#checkExistPhone").html("");
});

// 吊起手机App商店
$("#heqianming,#heqianmings").click(function() {
    //console.log(1111)
    layer.open({
        type: 2,
        shadeClose: false,
        content: '加载中'
    });
    if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {

        window.setTimeout(function() {
            //window.location.href="itms-services:///?action=download-manifest&url=https://files.honeytrip.cn/honeyfiles/ipaplist/honeytrip.plist";
            window.location.href="https://testflight.apple.com/join/r3WQOdTo";
        }, 2000)
    }
    if (navigator.userAgent.match(/android/i)) {
        // window.location.href = "qcx://taxi:9999/loading";//android app协议
        window.setTimeout(function() {
            //window.location.href = "https://fir.im/hpgn"; //android 下载地址
            //window.location.href = "https://fir.im/FMLX"; //android 下载地址
            window.location.href = "http://download.honeytrip.cn/honeyfiles/apk/honeyGo_v502.apk"; //android 下载地址
        }, 2000)
    }
});

// app分享url取值
// function parseUrl() {
// 	var url = window.location.search;
// 	console.log(url);
// 	var searchHref = url.replace('?', '');
// 	var params = searchHref.split('&');
// 	console.log(params)
// 	var returnParam = {};
// 	params.forEach(function(param) {
// 		var paramSplit = param.split('=');
// 		returnParam[paramSplit[0]] = paramSplit[1];
// 		console.log(returnParam)
// 	});
// 	return returnParam;
//
// };
// var params = parseUrl();
// var inviteCode;
// function validate(params) {
// 	//获取邀请码
//     inviteCode = getQueryString("accountId");
//     // inviteCode = "C3V3MD1";
//     $("#yqcode").val(inviteCode);
// };
//
// function getQueryString(name) {
//     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
//     var r = window.location.search.substr(1).match(reg);
//     if (r != null) return unescape(r[2]); return null;
// }
// validate(params);

// 已注册提示弹框
// $('.CenterHopLeft').on('touchstart', function() {
// 	$(".tankuang").hide();
// })
